const route = require('koa-router')();
const adminClass = require('../../model/adminClassify/class.js')

route.post('/admin/up_admin_classify',async(ctx,next)=>{
    let reqData = ctx.request.body

    if(!reqData.title){
        ctx.body = {
            code:400,
            msg:'title标题不能为空'
        }
    }else if(!reqData.iconPath){
        ctx.body = {
            code:400,
            msg:'iconPath图标不能为空'
        }
    }else if(!reqData.activeIconPath){
        ctx.body = {
            code:400,
            msg:'activeIconPath图标不能为空'
        }
    }else if(!reqData.billType){
        ctx.body = {
            code:400,
            msg:'billType不能为空'
        }
    }else{
        let all = await adminClass.find()
        if(all.length==0){
            reqData.id = 1
        }else{
            reqData.id = all[all.length-1].id+1
        }
        await adminClass.create(reqData)
        ctx.body = {
            code:200,
            msg:'ok'
        }
    }
    
})

module.exports = route